package com.snj.visangedu.studytime;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.Checkable;
import android.widget.RelativeLayout;

public class BellLayout extends RelativeLayout implements Checkable {
	
	final String NS = "http://schemas.android.com/apk/res/com.snj.visangedu";
	final String ATTR = "checkable";

	int checkableid;
	Checkable checkable;
		
	public BellLayout(Context context, AttributeSet attr) {
		super(context, attr);
		// TODO Auto-generated constructor stub
		
		checkableid = attr.getAttributeResourceValue(NS, ATTR, 0);

	}

	@Override
	public void setChecked(boolean checked) {
		// TODO Auto-generated method stub
		//Log.d("BellLayout", "checked");
		checkable = (Checkable)findViewById(checkableid);
		if(checkable == null)
		{
			//Log.d("BellLayout", "null");
			return;
		}
		checkable.setChecked(checked);
	}

	@Override
	public boolean isChecked() {
		// TODO Auto-generated method stub
		
		checkable = (Checkable)findViewById(checkableid);
		if(checkable == null) return false;
		
		return checkable.isChecked();
	}

	@Override
	public void toggle() {
		// TODO Auto-generated method stub
		Log.d("BellLayout", "toggled");
		checkable = (Checkable)findViewById(checkableid);
		if(checkable == null)
			return;
		
		checkable.toggle();
	}

}
